REQUIRES       = pistachio
LIBS           = allocator_avl
CXX_SRC_CC     = misc.cc new_delete.cc malloc_free.cc exception.cc

vpath %.cc         $(BASE_DIR)/src/base/cxx
vpath exception.cc $(REP_DIR)/src/base/cxx

#
# Here we define all symbols we want to hide in libsupc++ and libgcc_eh
#
LIBC_SYMBOLS   = malloc free calloc realloc \
                 abort fputc fputs fwrite \
                 stderr strcat strcpy strlen \
                 memset

#
# Take the right system libraries
#
LIBCXX_GCC     = $(shell $(CUSTOM_CXX_LIB) -print-file-name=libsupc++.a) \
                 $(shell $(CUSTOM_CXX_LIB) -print-file-name=libgcc_eh.a) \
                 $(shell $(CUSTOM_CXX_LIB) -print-libgcc-file-name)

#
# Dummy target used by the build system
#
SRC_S          = supc++.o
CXX_SRC        = $(sort $(CXX_SRC_CC))
CXX_OBJECTS    = $(addprefix $(OBJ_PREFIX), $(addsuffix .o,$(basename $(CXX_SRC))))
LOCAL_SYMBOLS  = $(patsubst %,--localize-symbol=%,$(LIBC_SYMBOLS))

#
# Rule to link all libc definitions and libsupc++ libraries
# and to hide after that the exported libc symbols
#
$(OBJ_PREFIX)$(SRC_S): $(CXX_OBJECTS)
	$(MSG_MERGE)$@
	$(VERBOSE)$(LD) -r $(CXX_OBJECTS) $(LIBCXX_GCC) -o $@.tmp
	$(MSG_CONVERT)$@
	$(VERBOSE)$(OBJCOPY) $(LOCAL_SYMBOLS) $@.tmp $@
	$(VERBOSE)$(RM) $@.tmp
